using System;
using System.Collections;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;

using WHC.Pager.Entity;
using Microsoft.Practices.EnterpriseLibrary.Data;
using WHC.Hotel.Entity;
using WHC.Hotel.IDAL;
using WHC.OrderWater.Commons;

namespace WHC.Hotel.DAL
{
	/// <summary>
	/// Customer 的摘要说明。
	/// </summary>
	public class Customer : BaseDAL<CustomerInfo>, ICustomer
	{
		#region 对象实例及构造函数

		public static Customer Instance
		{
			get
			{
				return new Customer();
			}
		}
		public Customer() : base("KF_Customer","ID")
		{
		}

		#endregion

		/// <summary>
		/// 将DataReader的属性值转化为实体类的属性值，返回实体类
		/// </summary>
		/// <param name="dr">有效的DataReader对象</param>
		/// <returns>实体类对象</returns>
		protected override CustomerInfo DataReaderToEntity(IDataReader dataReader)
		{
			CustomerInfo customerInfo = new CustomerInfo();
			SmartDataReader reader = new SmartDataReader(dataReader);
			
			customerInfo.ID = reader.GetInt32("ID");
			customerInfo.CustomerType = reader.GetString("CustomerType");
			customerInfo.Name = reader.GetString("Name");
			customerInfo.Sex = reader.GetString("Sex");
			customerInfo.IDCarType = reader.GetString("IDCarType");
			customerInfo.IDNumber = reader.GetString("IDNumber");
			customerInfo.Telephone = reader.GetString("Telephone");
			customerInfo.Source = reader.GetString("Source");
			customerInfo.CompanyName = reader.GetString("CompanyName");
			customerInfo.Address = reader.GetString("Address");
			customerInfo.RegistrationDate = reader.GetDateTime("RegistrationDate");
			customerInfo.Note = reader.GetString("Note");
			
			return customerInfo;
		}

		/// <summary>
		/// 将实体对象的属性值转化为Hashtable对应的键值
		/// </summary>
		/// <param name="obj">有效的实体对象</param>
		/// <returns>包含键值映射的Hashtable</returns>
        protected override Hashtable GetHashByEntity(CustomerInfo obj)
		{
		    CustomerInfo info = obj as CustomerInfo;
			Hashtable hash = new Hashtable(); 
			
 			hash.Add("CustomerType", info.CustomerType);
 			hash.Add("Name", info.Name);
 			hash.Add("Sex", info.Sex);
 			hash.Add("IDCarType", info.IDCarType);
 			hash.Add("IDNumber", info.IDNumber);
 			hash.Add("Telephone", info.Telephone);
 			hash.Add("Source", info.Source);
 			hash.Add("CompanyName", info.CompanyName);
 			hash.Add("Address", info.Address);
 			hash.Add("RegistrationDate", info.RegistrationDate);
 			hash.Add("Note", info.Note);
 				
			return hash;
		}

    }
}